#include <list>
#include <cv.h>
#include <highgui.h>

using namespace std;

struct HSV
{
	int H;
	int S;
	int V;
};
struct ChainCode
{
	unsigned char nValue;
	int nX;
	int nY;
};

class ImageProcessing
{
public:
	ImageProcessing();
	~ImageProcessing();

private:
	IplImage *pImage;
	IplImage *pImageGray;
	HSV* pHSV;
	list<ChainCode> lChain;
	list<ChainCode>::iterator iChain;
	int h;
	int w;
	int byteWidth;
	
public:
	int nErrorID;//RGBtoHSV(): 11>20
				//HSVtoRGB(): 21->30
				//FilterOnHSV(..): 31->40
				//MakeCannyEdge():41->50
				//CreateChainCode():51->60
				//ShowFeaturePoint():61->70
	bool LoadImage(char* filename);
	bool RGBtoHSV();
	bool HSVtoRGB();
	bool FilterOnHSV(int Hmin, int Hmax, int Smin, int Smax, int Vmin, int Vmax);
	void SetupGrayImage(unsigned char opt = 0);
	bool MakeCannyEdge();
	bool CreateChainCode();
	bool ShowFeaturePoint();
	IplImage* GetImageObj();
	IplImage* GetImageGrayObj();
	HSV* GetHSV();
	char* ErrorReport(int ID);
private:
	void ConvertRGBtoHSV(unsigned char r, unsigned char g, unsigned char b, HSV &Output);
	void ConvertHSVtoRGB(HSV in,unsigned char &r,unsigned char &g,unsigned char &b);
	int FindChainCode(int x, int y,int &nextX, int &nextY,unsigned char preValue, unsigned char grayValue);
	void Test_PrintChainCode();
};